

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  <meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>LazyIO &mdash; Ceph Documentation</title>
  

  
  <link rel="stylesheet" href="../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/graphviz.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script>
        <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/sphinx_highlight.js"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../genindex/" />
    <link rel="search" title="Search" href="../../search/" />
    <link rel="next" title="目录分片的配置" href="../dirfrags/" />
    <link rel="prev" title="CephFS 目录条目名字规范化和大小写折叠" href="../charmap/" /> 
</head>

<body class="wy-body-for-nav">

   
  <header class="top-bar">
    <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../../" class="icon icon-home" aria-label="Home"></a></li>
          <li class="breadcrumb-item"><a href="../">Ceph 文件系统</a></li>
      <li class="breadcrumb-item active">LazyIO</li>
      <li class="wy-breadcrumbs-aside">
            <a href="../../_sources/cephfs/lazyio.rst.txt" rel="nofollow"> View page source</a>
      </li>
  </ul>
  <hr/>
</div>
  </header>
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #eee" >
          

          
            <a href="../../" class="icon icon-home"> Ceph
          

          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search/" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../start/">Ceph 简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../install/">安装 Ceph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../cephadm/">Cephadm</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../rados/">Ceph 存储集群</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../">Ceph 文件系统</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../#cephfs">CephFS 入门</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id4">管理</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id5">挂载 CephFS</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../#id6">CephFS 内幕</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="../mds-states/"> MDS 的各种状态</a></li>
<li class="toctree-l3"><a class="reference internal" href="../posix/"> POSIX 兼容性</a></li>
<li class="toctree-l3"><a class="reference internal" href="../mds-journaling/"> MDS 日志记录</a></li>
<li class="toctree-l3"><a class="reference internal" href="../file-layouts/"> 文件布局</a></li>
<li class="toctree-l3"><a class="reference internal" href="../mdcache/"> 分布式元数据缓存</a></li>
<li class="toctree-l3"><a class="reference internal" href="../dynamic-metadata-management/"> CephFS 内的动态元数据管理</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cephfs-io-path/"> CephFS IO 路径</a></li>
<li class="toctree-l3"><a class="reference internal" href="../charmap/"> 大小写敏感和规范化</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#"> LazyIO</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#id1">启用 LazyIO</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id2">使用 LazyIO</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../dirfrags/"> 目录分片的配置</a></li>
<li class="toctree-l3"><a class="reference internal" href="../multimds/"> 多活 MDS 的配置</a></li>
<li class="toctree-l3"><a class="reference internal" href="../snapshots/"> 快照</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../#id7">故障排除和灾难恢复</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id9">更多细节</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../rbd/">Ceph 块设备</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../radosgw/">Ceph 对象网关</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mgr/">Ceph 管理器守护进程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mgr/dashboard/">Ceph 仪表盘</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../monitoring/">监控概览</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/">API 文档</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../architecture/">体系结构</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev/developer_guide/">开发者指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev/internals/">Ceph 内幕</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../governance/">项目管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../foundation/">Ceph 基金会</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../ceph-volume/">ceph-volume</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/general/">Ceph 版本（总目录）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/">Ceph 版本（索引）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../security/">Security</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../hardware-monitoring/">硬件监控</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../glossary/">Ceph 术语</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../jaegertracing/">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../translation_cn/">中文版翻译资源</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../">Ceph</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
<div id="dev-warning" class="admonition note">
  <p class="first admonition-title">Notice</p>
  <p class="last">This document is for a development version of Ceph.</p>
</div>
  <div id="docubetter" align="right" style="padding: 5px; font-weight: bold;">
    <a href="https://pad.ceph.com/p/Report_Documentation_Bugs">Report a Documentation Bug</a>
  </div>

  
  <section id="lazyio">
<h1>LazyIO<a class="headerlink" href="#lazyio" title="Permalink to this heading"></a></h1>
<p>LazyIO 放宽了 POSIX 语义。它允许缓冲读、写，即使一个文件同时被多个客户端上的多个应用打开时也允许。
缓存一致性由应用程序自己负责。</p>
<p>Libcephfs 从 nautilus 版起支持 LazyIO 功能。</p>
<section id="id1">
<h2>启用 LazyIO<a class="headerlink" href="#id1" title="Permalink to this heading"></a></h2>
<p>LazyIO 的启用方法有下面几种。</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">client_force_lazyio</span></code> 选项可以在全局范围内给 libcephfs 和 ceph-fuse
启用 LAZY_IO 。</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ceph_lazyio(...)</span></code> 和 <code class="docutils literal notranslate"><span class="pre">ceph_ll_lazyio(...)</span></code> 可以在 libcephfs 里的文件句柄上启用 LAZY_IO 。</p></li>
</ul>
</section>
<section id="id2">
<h2>使用 LazyIO<a class="headerlink" href="#id2" title="Permalink to this heading"></a></h2>
<p>LazyIO 包含两个方法： <code class="docutils literal notranslate"><span class="pre">lazyio_propagate()</span></code> 和 <code class="docutils literal notranslate"><span class="pre">lazyio_synchronize()</span></code> 。
启用了 LazyIO 时，写操作结果在调用 <code class="docutils literal notranslate"><span class="pre">lazyio_propagate()</span></code> 之后才对其它客户端可见。
一直到调用 <code class="docutils literal notranslate"><span class="pre">lazyio_synchronize()</span></code> 之前，读取的内容还是来自本地缓存
（暂且不管其它客户端对文件的更改）。</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">lazyio_propagate(int</span> <span class="pre">fd,</span> <span class="pre">loff_t</span> <span class="pre">offset,</span> <span class="pre">size_t</span> <span class="pre">count)</span></code> - 确保客户端的写操作缓冲，位于某个特定范围（位于 offset+count 范围内的）内的，
已经散播给了共享的文件。如果 offset 和 count 都是 0 ，
就对整个文件执行此操作。当前还只支持这样操作。</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">lazyio_synchronize(int</span> <span class="pre">fd,</span> <span class="pre">loff_t</span> <span class="pre">offset,</span> <span class="pre">size_t</span> <span class="pre">count)</span></code> - 确保客户端在一次顺序读调用时，能够读取到更新过的文件，也就是包含了所有其它客户端散播来的写操作。在 CephFS 里是这样实现的，
让相关 inode 下的文件缓存失效、也就意味着强制此客户端重新获取、
重新缓存已更新文件的数据。同时，如果发起调用的客户端它的写缓存不干净
（没有散播出去）的话， lazyio_synchronize() 也会刷回它。</p></li>
</ul>
<p>下面的实例（使用了 libcephfs ），是在一个并行应用程序里，
某个特定的客户端、文件描述符的 I/O 循环样本：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">/*</span> <span class="n">Client</span> <span class="n">a</span> <span class="p">(</span><span class="n">ca</span><span class="p">)</span> <span class="n">opens</span> <span class="n">the</span> <span class="n">shared</span> <span class="n">file</span> <span class="n">file</span><span class="o">.</span><span class="n">txt</span> <span class="o">*/</span>
<span class="nb">int</span> <span class="n">fda</span> <span class="o">=</span> <span class="n">ceph_open</span><span class="p">(</span><span class="n">ca</span><span class="p">,</span> <span class="s2">&quot;shared_file.txt&quot;</span><span class="p">,</span> <span class="n">O_CREAT</span><span class="o">|</span><span class="n">O_RDWR</span><span class="p">,</span> <span class="mi">0644</span><span class="p">);</span>

<span class="o">/*</span> <span class="n">Enable</span> <span class="n">LazyIO</span> <span class="k">for</span> <span class="n">fda</span> <span class="o">*/</span>
<span class="n">ceph_lazyio</span><span class="p">(</span><span class="n">ca</span><span class="p">,</span> <span class="n">fda</span><span class="p">,</span> <span class="mi">1</span><span class="p">));</span>

<span class="k">for</span><span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">num_iters</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
    <span class="n">char</span> <span class="n">out_buf</span><span class="p">[]</span> <span class="o">=</span> <span class="s2">&quot;fooooooooo&quot;</span><span class="p">;</span>

    <span class="n">ceph_write</span><span class="p">(</span><span class="n">ca</span><span class="p">,</span> <span class="n">fda</span><span class="p">,</span> <span class="n">out_buf</span><span class="p">,</span> <span class="n">sizeof</span><span class="p">(</span><span class="n">out_buf</span><span class="p">),</span> <span class="n">i</span><span class="p">);</span>
    <span class="o">/*</span> <span class="n">Propagate</span> <span class="n">the</span> <span class="n">writes</span> <span class="n">associated</span> <span class="k">with</span> <span class="n">fda</span> <span class="n">to</span> <span class="n">the</span> <span class="n">backing</span> <span class="n">storage</span><span class="o">*/</span>
    <span class="n">ceph_propagate</span><span class="p">(</span><span class="n">ca</span><span class="p">,</span> <span class="n">fda</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>

    <span class="o">/*</span> <span class="n">The</span> <span class="n">barrier</span> <span class="n">makes</span> <span class="n">sure</span> <span class="n">changes</span> <span class="n">associated</span> <span class="k">with</span> <span class="nb">all</span> <span class="n">file</span> <span class="n">descriptors</span>
    <span class="n">are</span> <span class="n">propagated</span> <span class="n">so</span> <span class="n">that</span> <span class="n">there</span> <span class="ow">is</span> <span class="n">certainty</span> <span class="n">that</span> <span class="n">the</span> <span class="n">backing</span> <span class="n">file</span>
    <span class="ow">is</span> <span class="n">upto</span> <span class="n">date</span> <span class="o">*/</span>
    <span class="n">application_specific_barrier</span><span class="p">();</span>

    <span class="n">char</span> <span class="n">in_buf</span><span class="p">[</span><span class="mi">40</span><span class="p">];</span>
    <span class="o">/*</span> <span class="n">Calling</span> <span class="n">ceph_lazyio_synchronize</span> <span class="n">here</span> <span class="n">will</span> <span class="n">ascertain</span> <span class="n">that</span> <span class="n">ca</span> <span class="n">will</span>
    <span class="n">read</span> <span class="n">the</span> <span class="n">updated</span> <span class="n">file</span> <span class="k">with</span> <span class="n">the</span> <span class="n">propagated</span> <span class="n">changes</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">read</span>
    <span class="n">stale</span> <span class="n">cached</span> <span class="n">data</span> <span class="o">*/</span>
    <span class="n">ceph_lazyio_synchronize</span><span class="p">(</span><span class="n">ca</span><span class="p">,</span> <span class="n">fda</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
    <span class="n">ceph_read</span><span class="p">(</span><span class="n">ca</span><span class="p">,</span> <span class="n">fda</span><span class="p">,</span> <span class="n">in_buf</span><span class="p">,</span> <span class="n">sizeof</span><span class="p">(</span><span class="n">in_buf</span><span class="p">),</span> <span class="mi">0</span><span class="p">);</span>

    <span class="o">/*</span> <span class="n">A</span> <span class="n">barrier</span> <span class="ow">is</span> <span class="n">required</span> <span class="n">here</span> <span class="n">before</span> <span class="n">returning</span> <span class="n">to</span> <span class="n">the</span> <span class="nb">next</span> <span class="n">write</span>
    <span class="n">phase</span> <span class="n">so</span> <span class="k">as</span> <span class="n">to</span> <span class="n">avoid</span> <span class="n">overwriting</span> <span class="n">the</span> <span class="n">portion</span> <span class="n">of</span> <span class="n">the</span> <span class="n">shared</span> <span class="n">file</span> <span class="n">still</span>
    <span class="n">being</span> <span class="n">read</span> <span class="n">by</span> <span class="n">another</span> <span class="n">file</span> <span class="n">descriptor</span> <span class="o">*/</span>
    <span class="n">application_specific_barrier</span><span class="p">();</span>
<span class="p">}</span>
</pre></div>
</div>
</section>
</section>



<div id="support-the-ceph-foundation" class="admonition note">
  <p class="first admonition-title">Brought to you by the Ceph Foundation</p>
  <p class="last">The Ceph Documentation is a community resource funded and hosted by the non-profit <a href="https://ceph.io/en/foundation/">Ceph Foundation</a>. If you would like to support this and our other efforts, please consider <a href="https://ceph.io/en/foundation/join/">joining now</a>.</p>
</div>


           </div>
           
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="../charmap/" class="btn btn-neutral float-left" title="CephFS 目录条目名字规范化和大小写折叠" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="../dirfrags/" class="btn btn-neutral float-right" title="目录分片的配置" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2016, Ceph authors and contributors. Licensed under Creative Commons Attribution Share Alike 3.0 (CC-BY-SA-3.0).</p>
  </div>

   

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>